package Jets.shapes 
{
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;

	public class JPolygon extends Sprite 
	{
		private var ms_nSize:int = 10;
		private var ms_nSide:int = 3;
		private var ms_nFillColor:int;
		private var ms_nLine:int = 1;
		private var ms_nLineColor:int;
		/**
		 * 画多边形图形
		 * @param x 中心坐标
		 * @param y 中心坐标
		 * @param side 边数 大于等于3
		 * @param radis 半径
		 */
		public function JPolygon(size:int=50,side:uint=3,fillColor:Number=0,line:int=1,lineColor:int=0) 
		{
			ms_nSize = size;
			ms_nSide = side;
			ms_nFillColor = fillColor;
			ms_nLine = line;
			ms_nLineColor = lineColor;
			drawPolygon();
		}
		private function drawPolygon():void
		{
			this.graphics.clear();
			if(ms_nLine)
			{
				this.graphics.lineStyle(ms_nLine,ms_nLineColor);
			}
			this.graphics.beginFill(ms_nFillColor);
			var arr:Array = new Array();
			for(var i:int =0;i<ms_nSide;i++)
			{
				var p:Point = new Point();
				var vertexDegree:Number = 360/ms_nSide*i*Math.PI/180;
				p=Point.polar(ms_nSize,vertexDegree);
				arr.push(p);
			}
			this.graphics.moveTo(arr[0].x,arr[0].y);
			for (i=1; i<arr.length; i++) 
			{
				this.graphics.lineTo(arr[i].x,arr[i].y);
			}
			this.graphics.lineTo(arr[0].x,arr[0].y);
			this.graphics.endFill();
		}
		
		/**
		 * 画多边形图形
		 * @param g Graphics
		 * @param x 中心坐标
		 * @param y 中心坐标
		 * @param side 边数 大于等于3
		 * @param radis 半径
		 */
		static public function DrawPolygon(g:Graphics,size:int=50,side:uint=3,fillColor:Number=0,line:int=1,lineColor:int=0,isClear:Boolean=false):void
		{
			if(isClear)
			{
				g.clear();
			}
			if(line)
			{
				g.lineStyle(line,lineColor);
			}
			g.beginFill(fillColor);
			var arr:Array = new Array();
			for(var i:int =0;i<side;i++)
			{
				var p:Point = new Point();
				var vertexDegree:Number = 360/side*i*Math.PI/180;
				p=Point.polar(size,vertexDegree);
				arr.push(p);
			}
			g.moveTo(arr[0].x,arr[0].y);
			for (i=1; i<arr.length; i++) 
			{
				g.lineTo(arr[i].x,arr[i].y);
			}
			g.lineTo(arr[0].x,arr[0].y);
			g.endFill();
		}
	}
}